import {BasicColumn, FormSchema} from '/@/components/Table';
import {UploadBizType} from '/@/enums/uploadEnum';

import {render} from "/@/utils/common/renderUtils";

// 定义可选择的组件类型
export enum ComponentTypes {
  Default = 'layouts/default/index',
  IFrame = 'sys/iframe/FrameBlank',
}

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 180,
    align: 'left',
  },
  {
    title: '图片',
    dataIndex: 'logo',
    slots: { customRender: 'logo' },
    width: 60,
  },
  {
    title: '显示',
    dataIndex: 'showStatus',
    customRender: ({text}) => {
      let color = 'green'
      if (text === '0') {
        color = 'red'
      }
      return render.renderTag(render.renderDict(text, 'show_status'), color)
    },
    width: 64,
  },
  {
    title: '排序',
    dataIndex: 'sortNo',
    width: 50,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '分类名称',
    component: 'Input'
  }
];

export const formSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    label: '分类名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'parentId',
    label: '上级分类',
    helpMessage: '如果不选择, 默认就是顶级分类',
    component: 'TreeSelect',
    required: false,
    componentProps: {
      fieldNames: {
        title: 'name',
        key: 'id',
        value: 'id',
      },
      dropdownStyle: {
        maxHeight: '50vh'
      },
      getPopupContainer: (node) => node.parentNode
    },
  },
  {
    label: '图片',
    field: 'logo',
    component: 'JImageUpload',
    componentProps: {
      fileMax:1,
      bizType: UploadBizType.GENERAL_IMAGE
    },
  },

  {
    field: 'keywords',
    label: '关键字',
    helpMessage: '用于网站搜索引擎的优化',
    component: 'Select',
    componentProps: {
      mode: 'tags',
      tokenSeparators: [',']
    }
  },

  {
    field: 'sortNo',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 1,
    componentProps: {
      size: 'middle',
      style: {
        width: '100%'
      }
    }
  },

  {
    field: 'showStatus',
    label: '显示状态',
    required: true,
    defaultValue: '1',
    helpMessage: '如果不显示会导致小程序、h5不显示该分类以及该分类下的所有商品',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'show_status',
      type:'radio',
    }
  },

  {
    label: '描述',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入分类描述',
      rows: 3,
    },
  }
];
